package com.lzw.bluetoothpractice.Adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.Activitys.HealthyDetailActivity;
import com.lzw.bluetoothpractice.Activitys.HealthyMessagesActivity;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.Models.Article;
import com.lzw.bluetoothpractice.R;
import com.lzw.bluetoothpractice.bean.HealthyMessageListBean;
import com.lzw.bluetoothpractice.bean.RecommendDoctorBean;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

public class HealthyMessagesAdapter extends RecyclerView.Adapter<HealthyMessagesAdapter.ViewHolder> {


    private List<HealthyMessageListBean.DataBean> datas = new ArrayList<>();
    View itemView;
    Context mcontext;
    public void updateData(List<HealthyMessageListBean.DataBean> data) {
        if (this.datas == null) {
            this.datas = new ArrayList<>();
        }
        this.datas.clear();
        this.datas.addAll(data);
        notifyDataSetChanged();
    }

    public HealthyMessagesAdapter(Context mcontext) {
        this.mcontext = mcontext;

    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        itemView= LayoutInflater.from(mcontext).inflate(R.layout.healthy_message,parent,false);

        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        HealthyMessageListBean.DataBean dataBean = datas.get(position);
        Glide.with(mcontext).load(AppConfig.BASE_URL+dataBean.getMessagePic()).into(holder.imageHealth);

       // Glide.with(mcontext).load(dataBean.getMessagePic()).into(holder.imageHealth);
        holder.textHealth.setText(dataBean.getMessageTitle());
        holder.dateHealth.setText(dataBean.getCreateTime().toString());
        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                Bundle bundle = new Bundle();
                // bundle.putSerializable("conversation", conversationEntrance);
                bundle.putSerializable("articleID", dataBean.getMessageId());
                intent.setClass(mcontext, HealthyDetailActivity.class);
                if (bundle != null) {
                    intent.putExtras(bundle);
                }
                mcontext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        View view;
        ImageView imageHealth;
        TextView  textHealth;
        TextView  dateHealth;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            view=itemView;
            imageHealth=view.findViewById(R.id.imageHealth);
            textHealth=view.findViewById(R.id.textHealth);
            dateHealth=view.findViewById(R.id.dateHealth);

        }
    }

}
